import { ref } from 'vue';
const timer = ref<any>(null);

/**
 * @description use to init a interval timer
 * @params cb:callback fucntion  interval: timer interval,default to 10000ms
 * @returns startTimer: to start the timer, closeTimer：close Timer to avoid memory leak
 */
export default function useIntervalInvoke() {
  const startTimer = (cb: () => any, interval = 10000) => {
    timer.value = setInterval(cb, interval);
  };
  const closeTimer = () => {
    clearInterval(timer.value);
  };
  return {
    startTimer,
    closeTimer,
  };
}
